import { Body, Controller, Get, Post, Res } from '@nestjs/common';
import { AuthService } from './auth.service';
import { Response } from 'express';
import { Public } from '../../../common/decorators/public.decorator';
import { getPublicKey } from '../../../common/utils/rsa.util';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Public()
  @Get('get-captcha')
  async getCaptcha(@Res() res: Response) {
    const { key, captcha } = await this.authService.getLoginCaptcha();
    res.setHeader('Content-Disposition', key);
    res.type('image/svg+xml');
    res.send(captcha.data);
  }

  @Public()
  @Get('get-public-key')
  getPublicKey(): string {
    return getPublicKey();
  }

  @Public()
  @Post('encrypt')
  rsaEncrypt(@Body() body: any): string {
    return this.authService.rsaEncrypt(body);
  }
}
